package com.lagou.vo;

import javax.servlet.http.HttpSession;
import java.io.Serializable;
import java.util.Date;

/**
 * @author: wudong
 * @create: 2021-08-03 18:10
 **/
public class UserInfo implements Serializable {
    public static final String sessionKey = "userLogin";

    private String username;
    private Date loginTime;

    public static UserInfo buildFromSession(HttpSession session){
        return (UserInfo)session.getAttribute(sessionKey);
    }

    public static UserInfo build(String username){
        UserInfo userInfo = new UserInfo();
        userInfo.setUsername(username);
        userInfo.setLoginTime(new Date());
        return userInfo;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public Date getLoginTime() {
        return loginTime;
    }

    public void setLoginTime(Date loginTime) {
        this.loginTime = loginTime;
    }

    @Override
    public String toString() {
        return "UserInfo{" +
                "username='" + username + '\'' +
                ", loginTime=" + loginTime +
                '}';
    }
}
